package com.crm.mapper;

import com.crm.domain.SysMenu;
import org.apache.ibatis.annotations.*;

@Mapper
public interface SysMenuMapper {
    /**
     * 根据菜单编号获取详细信息
     */
    @Select("select * from sys_menu where menu_id = #{menuId}")
    String selectMenuById(Long menuId);

    /**
     * 根据角色ID查询菜单树信息
     */
    @Select("select distinct m.menu_id, m.parent_id from sys_menu m " )
    Object selectMenuListByRoleId(Long roleId);

    /**
     * 新增保存菜单信息
     *
     * @param menu 菜单信息
     * @return 结果
     */

    @Insert("insert into sys_menu values(#{menuId},#{menuName},#{parentId},#{orderNum},#{path},#{component},#{isFrame},#{isCache},#{menuType},#{visible},#{status},#{perms},#{icon},#{createBy},#{createTime},#{updateBy},#{updateTime},#{remark})")
    int insertMenu(SysMenu menu);
    /**
     * 修改菜单
     */
    @Update("UPDATE sys_menu\n" +
            "SET \n" +
            "    menu_name = #{menuName},\n" +
            "    parent_id = #{parentId},\n" +
            "    order_num = #{orderNum},\n" +
            "    path = #{path},\n" +
            "    component = #{component},\n" +
            "    is_frame = #{isFrame},\n" +
            "    is_cache = #{isCache},\n" +
            "    menu_type = #{menuType},\n" +
            "    visible = #{visible},\n" +
            "    status = #{status},\n" +
            "    perms = #{perms},\n" +
            "    icon = #{icon},\n" +
            "    create_by = #{createBy},\n" +
            "    create_time = #{createTime},\n" +
            "    update_by = #{updateBy},\n" +
            "    update_time = #{updateTime},\n" +
            "    remark = #{remark}\n" +
            "WHERE menu_id = #{menuId};")
    Integer updateMenu(SysMenu menu);

    /**
     * 删除菜单
     */
    @Delete("delete from sys_menu where menu_id = #{menuId}")
    Integer deleteMenuById(Long menuId);
}
